//
//  ZWTuYaViewController.m
//  MyTest
//
//  Created by rayootech on 15/9/26.
//  Copyright (c) 2015年 rayootech. All rights reserved.
//

#import "ZWTuYaViewController.h"
#import "UIImage+ZWJieTu.h"
#import "MBProgressHUD+MJ.h"
#import "ZWView.h"
@interface ZWTuYaViewController ()
@property (weak, nonatomic) IBOutlet ZWView *paintView;
- (IBAction)save;
- (IBAction)clear;
- (IBAction)back;
@end

@implementation ZWTuYaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.title=@"涂鸦";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)save{
    // 1.截图
    UIImage *image = [UIImage captureWithView:self.paintView];
    // 2.保存到图片
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
 
}
- (IBAction)clear{

    [self.paintView clear];
}
- (IBAction)back{
   [self.paintView back];
}

/**
 保存图片操作之后就会调用
 */
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error) {// 保存失败
        [MBProgressHUD showError:@"保存到相册失败"];
    } else {// 保存成功
        [MBProgressHUD showSuccess:@"成功保存到相册"];
    }
}

@end
